--
-- DailyWishWorld.lua
-- Created by IntelliJ IDEA.
-- User: yao.chen
-- Date: 2018/12/27
-- 祝福世界

local ClassRef = app.mvc.createPanelClass(...)

local MapBlessIconRender = require("app.worldMap.views.renders.MapBlessIconRender")

local BLESS_NUM_STR = L("lua_code_text_121")

function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.DailyNodeWishWorld))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end

function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

function ClassRef:init()
    self.super.init(self, data)

    local mapPanel = self._ui["Panel/Panel_map"]
    local renders = {0,0,0,0,0}
    for i=1,5 do
        local render = MapBlessIconRender.create(mapPanel:getChildByName("Panel_" .. i))
        render:onBtnClick(handler(self, self._onClickRender))
        renders[i] = render
    end
    self._renders = renders

    self._numText = self._ui["Panel/Panel_bom/tips"]
end

function ClassRef:_onClickRender(render)
    executeFunc(self._onOperate, "openBless", render:getData())
end

-- maps = {MapInfo, ...}
function ClassRef:refresh(maps)
    if not maps then return end
    for i,render in ipairs(self._renders) do
        render:setData(maps[i])
    end
end

function ClassRef:refreshBlessTimes(blessTimes)
    self._numText:setString(string.format(BLESS_NUM_STR, blessTimes))
end

function ClassRef:onOperate(cb)
    self._onOperate = cb
end

return ClassRef

